package com.cgnpc.scp.manager.controller;

import com.cgnpc.cud.annotation.OperatorType;
import com.cgnpc.cud.annotation.UBA;
import com.cgnpc.cud.core.domain.AjaxResult;
import com.cgnpc.framework.userinfo.CurrentUser;
import com.cgnpc.scp.achievement.pojo.IdReq;
import com.cgnpc.scp.common.bean.MyPageResult;
import com.cgnpc.scp.common.utils.AjaxResultUtil;
import com.cgnpc.scp.manager.mybatis.entity.UsualPhraseConfig;
import com.cgnpc.scp.manager.service.UsualPhraseConfigService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/scp/data/usualphrase")
public class UsualPhraseConfigController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(UsualPhraseConfigController.class);

    @Autowired
    private CurrentUser currentUser;

    @Autowired
    private MessageSource messageSource;

    @Autowired
    private UsualPhraseConfigService usualPhraseConfigService;

    /**********************************
     * 用途说明: 查询审批常用语列表
     * 参数说明 re
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="查询审批常用语列表")
    @UBA(module = "后台管理", action = "审批常用语列表查询", channel = OperatorType.Page)
    @RequestMapping(value = "/listPage", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResult listPage(HttpServletRequest request, @RequestBody UsualPhraseConfig req) {
        MyPageResult<UsualPhraseConfig> result = usualPhraseConfigService.queryPageList(req);
        return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,result);
    }

    /**********************************
     * 用途说明: 保存审批常用语
     * 参数说明 SaveAwardReq
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="保存审批常用语")
    @UBA(module = "后台管理", action = "保存审批常用语", channel = OperatorType.Button)
    @RequestMapping(value = "/save", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResult save(HttpServletRequest request, @RequestBody UsualPhraseConfig config) {
        UsualPhraseConfig result = usualPhraseConfigService.save(config);

        if (result != null)
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,result);
        else
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,"保存失败!");
    }

    /**********************************
     * 用途说明: 根据ID 审批常用语 详细信息
     * 参数说明 id
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="根据ID 审批常用语 详细信息")
    @UBA(module = "后台管理", action = "查看审批常用语详情", channel = OperatorType.Button)
    @RequestMapping(value = "/getInfoById", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResult getInfoById(HttpServletRequest request, @RequestBody IdReq req) {
        UsualPhraseConfig result = usualPhraseConfigService.getById(req.getId());
        if (result != null)
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,result);
        else
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,"查询失败，没有找到对应记录!");
    }

    /**********************************
     * 用途说明: 删除 审批常用语
     * 参数说明
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="删除审批常用语")
    @UBA(module = "后台管理", action = "删除审批常用语", channel = OperatorType.Button)
    @RequestMapping(value = "/delByIds", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResult delByIds(HttpServletRequest request, @RequestBody List<String> ids) {
        if (usualPhraseConfigService.delByIds(ids))
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource);
        else
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,"删除失败!");
    }
}
